<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ taglib uri="http://www.springframework.org/tags" prefix="spring"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<%@taglib uri="http://www.springframework.org/tags/form" prefix="form"%>

<div class="box m">
	<div class="btitle path">
		<a title="<spring:message code="top.header.homepage" />" href="goHomePage.html"><spring:message code="top.header.homepage" /></a>&nbsp;»&nbsp; <a
			href="goContact.html"><spring:message code="top.header.contact" /></a>
	</div>
	<div class="bCt productLs">
		<div>${contact.description }</div>
		<div class="iframe">${contact.embededMap }</div>

		<form:form method="post" enctype="multipart/form-data" modelAttribute="messageInfo" action="sendMessage.html" onsubmit="return validateForm();">
			<c:if test="${not empty message }">
				<div style="color: green;">${message}</div>
			</c:if>
			<table class="guimail" align="left" width="700px">
				<form:hidden path="to" />
				<tbody>
					<tr>
						<td><spring:message code="contact.form.name" /></td>
						<td><form:input path="name" /></td>
					</tr>
					<tr>
						<td><spring:message code="contact.form.phone" /></td>
						<td><form:input path="phone" /></td>
					</tr>
					<tr>
						<td><spring:message code="contact.form.email" /></td>
						<td><form:input path="from" /></td>
					</tr>
					<tr>
						<td><spring:message code="contact.form.subject" /></td>
						<td><form:input path="subject" /></td>
					</tr>
					<tr>
						<td><spring:message code="contact.form.content" /></td>
						<td><form:textarea path="content" /></td>
					</tr>
					<tr>
						<td></td>
						<td><input value="<spring:message code="contact.form.submit" />" type="submit">&nbsp;<input
							value=" <spring:message code="contact.form.reset" /> " type="reset"></td>
					</tr>
				</tbody>
			</table>
		</form:form>
	</div>
</div>

<script type="text/javascript">
	function validateForm() {
		if ($('#name').val().trim().length==0) {
			$('#name').css('border-color','red');
			return false;
		} else {
			$('#name').css('border-color','');
		}

		if (!validateEmail($('#from').val())) {
			$('#from').css('border-color','red');
			return false;
		} else {
			$('#from').css('border-color','');
		}
		
		if ($('#subject').val().trim().length==0) {
			$('#subject').css('border-color','red');
			return false;
		} else {
			$('#subject').css('border-color','');
		}
		
		if ($('#content').val().trim().length==0) {
			$('#content').css('border-color','red');
			return false;
		} else {
			$('#content').css('border-color','');
		}
		if (!validateEmail($('#to').val())) {
			return false;
		}
		
		return true;
	}

	function validateEmail(email) {
		var re = /^(([^<>()[\]\\.,;:\s@\"]+(\.[^<>()[\]\\.,;:\s@\"]+)*)|(\".+\"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/;
		return re.test(email);
	}
</script>